package com.vca.front.controller;

import com.vca.common.request.MiniQrCodeRequest;
import com.vca.common.request.PhoneDecryptionRequest;
import com.vca.common.request.RegisterThirdUserRequest;
import com.vca.common.request.WxBindingPhoneVoRequest;
import com.vca.common.response.LoginResponse;
import com.vca.common.result.CommonResult;
import com.vca.front.service.UserCenterService;
import com.vca.service.service.WechatNewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenbing
 * @date 2022/10/8   15:32
 */
@Slf4j
@RestController("WeChatFrontController")
@RequestMapping("api/front/wechat")
@Api(tags = "微信 -- 开放平台")
public class WeChatController {

    @Autowired
    private UserCenterService userCenterService;

    @Autowired
    private WechatNewService wechatNewService;

    /**
    * @Description:微信登录小程序授权登录
    * @Author: chenBing
    * @Date: 2022/10/8
    */
    @ApiOperation(value = "微信登录小程序授权登录")
    @RequestMapping(value = "/authorize/program/login", method = RequestMethod.POST)
    public CommonResult<LoginResponse> programLogin(@RequestParam String code, @RequestBody @Validated RegisterThirdUserRequest request) {
        return CommonResult.success(userCenterService.weChatAuthorizeProgramLogin(code, request));
    }

    /**
    * @Description:微信注册绑定手机号
    * @Author: chenBing
    * @Date: 2022/10/8
    */
    @ApiOperation(value = "微信注册绑定手机号")
    @RequestMapping(value = "/register/binding/phone", method = RequestMethod.POST)
    public CommonResult<LoginResponse> registerBindingPhone(@RequestBody @Validated WxBindingPhoneVoRequest request) {
        return CommonResult.success(userCenterService.registerBindingPhone(request));
    }

    /**
     *@Description:手机号解密
     *@author:chenbing
     *@date 2022/12/20 13:11
     */
    @ApiOperation(value = "手机号解密")
    @RequestMapping(value = "/phone/decryption",method = RequestMethod.POST)
    public CommonResult<String> phoneDecryption(@RequestBody PhoneDecryptionRequest request){
        return CommonResult.success(userCenterService.phoneDecryption(request));
    }

    //@PreAuthorize("hasAuthority('admin:wechat:config')")
    @ApiOperation(value = "生成小程序预览二维码")
    @RequestMapping(value = "/getMiniQrCode", method = RequestMethod.POST)
    public CommonResult<String> getMiniQrCode(@RequestBody MiniQrCodeRequest request){
        return CommonResult.success(wechatNewService.getWxaCode(request));
    }
}
